<template>
    <div>
        <city-header></city-header>
        <city-search></city-search>
        <city-list 
        :city="city" 
        :hot="hotCities" 
        :newcity="cities"
        :letters="letter"></city-list>
        <city-alphabet 
        :cities="cities"
        @change="handleChange"></city-alphabet>
    </div>
</template>

<script>
import axios from 'axios'
import CityAlphabet from './components/Alphabet.vue'
import CityList from './components/CityList.vue'
import CityHeader from './components/CityHeader.vue'
import CitySearch from './components/inputHeader.vue'
export default {
    name: 'City',
    components:{
        CityHeader,
        CitySearch,
        CityList,
        CityAlphabet
    },
    data () {
        return {
            city: '',
            cities: {},
            hotCities: [],
            letter:''
        }
    },
    methods: {
        getCityInfo () {
            axios.get('/api/city.json')
            .then(this.handleGetCityInfo)
        },
        handleGetCityInfo (res) {
           res = res.data
           if(res.ret && res.data){
            let data = res.data
            this.city = data.city
            this.hotCities = data.hotCities
            this.cities = data.cities
           }
        },
        handleChange(letter){
            this.letter = letter
        }
    },
    mounted () {
        this.getCityInfo()
    }
    
}
</script>
